<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="时间区间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="handleTimestamp"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" fixed align="center" width="80">
        <template scope="scope">
          <span>{{scope.$index + 1}} </span>
        </template>
      </el-table-column>
      <el-table-column label="设备IP" align="center" prop="nodeIp"/>
      <el-table-column label="设备名称" align="center" prop="nodeName"/>
      <el-table-column label="进出口类型" align="center" prop="nodeType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.node_type" :value="scope.row.nodeType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="进出口状态" align="center" prop="nodeStatus">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.node_status" :value="scope.row.nodeStatus"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="进/出数量" align="center" prop="trafficNum"/>
    </el-table>
  </div>
</template>
<script>
  import { clientUrl } from "@/api/client";

  export default {
    name: "index",
    dicts: ['node_type','node_status'],
    data(){
      return{
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 弹出层标题
        open: false,
        // 日期范围
        dateRange:[],
        //列表
        dataList:[],
        // 查询参数
        queryParams: {
          url:'/api/wec/GetNodeInOutInfo',
          serviceCode: 'getNodeInOutInfo',
          startTime:undefined,
          endTime:undefined,
        },
      }
    },

    created() {
      this.resetQuery();
    },

    methods:{
      /** 查询列表 */
      getList() {
        this.loading = true;
        clientUrl(this.queryParams).then(response => {
          let data = JSON.parse(response.data.data)
          this.dataList = data.statList;
          this.loading = false;
        });
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.getList();
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.dateRange = [this.parseTime(new Date(),'{y}-{m}-{d}'),this.parseTime(new Date(),'{y}-{m}-{d}')];
        this.handleTimestamp();
        this.handleQuery();
      },

      handleTimestamp(){
        this.queryParams.startTime = undefined;
        this.queryParams.endTime = undefined;
        if(this.dateRange == null || !this.dateRange.length>0) this.dateRange = [this.parseTime(new Date(),'{y}-{m}-{d}'),this.parseTime(new Date(),'{y}-{m}-{d}')];
        if(this.dateRange)this.queryParams.startTime = this.appendFix(this.dateRange[0],1);
        if(this.dateRange)this.queryParams.endTime =  this.appendFix(this.dateRange[1],2);
      }
    }
  }
</script>

<style scoped>

</style>
